package com.yanqu.road.server.manager.activity.daomu;

import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.daomu.*;
import com.yanqu.road.entity.activity.daomu.config.*;
import com.yanqu.road.entity.activity.daomu.data.DaoMuActivityUserOfferRewardData;
import com.yanqu.road.entity.activity.daomu.enums.DaoMuNpcStatusEnum;
import com.yanqu.road.entity.activity.daomu.param.DaoMuAttReportRes;
import com.yanqu.road.entity.activity.daomu.param.DaoMuCreateNpcRes;
import com.yanqu.road.entity.activity.daomu.param.DaoMuOpenBoxRes;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.exception.BusinessException;
import com.yanqu.road.logic.bussiness.activity.DaoMuActivityBusiness;
import com.yanqu.road.logic.bussiness.servercenter.ActivityBussiness;
import com.yanqu.road.logic.helper.ActivityHelper;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.activity.DaoMuProto;
import com.yanqu.road.server.TempCrossMgr;
import com.yanqu.road.server.manager.activity.ActivityMgr;
import com.yanqu.road.server.manager.activity.daomu.pvp.DaoMuActivityPvp;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;
import com.yanqu.road.utils.string.StringUtils;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public class DaoMuActivityMgr extends TempCrossMgr {

    //活动Map
    static Map<Integer, DaoMuActivity> activityMap = new ConcurrentHashMap<>();

    @Override
    public boolean removeExpireData() throws Exception {
        List<Integer> acList = new ArrayList<>();
        long nowTime = System.currentTimeMillis();
        for (Integer activityId : activityMap.keySet()) {
            DaoMuActivity activity = activityMap.get(activityId);
            // 展示期过3天后移除内存
            if (activity == null || activity.getDaoMuActivityConfig() == null || activity.getDaoMuActivityConfig().getActivityInfo() == null
                    || nowTime > activity.getDaoMuActivityConfig().getActivityInfo().getEndShowTime() * 1000 + 3 * DateHelper.DAY_MILLIONS) {
                acList.add(activityId);
            }
        }
        for (Integer activityId : acList) {
            activityMap.remove(activityId);
        }
        return true;
    }

    @Override
    public boolean init() throws Exception {
        return reload();
    }

    /**
     * 加载活动配置
     * @return
     * @throws Exception
     */
    @Override
    public boolean reloadConfig() throws Exception {
        getLogger().info("DaoMuActivityMgr reloadConfig start");
        for (DaoMuActivity daoMuActivity : activityMap.values()) {
            DaoMuActivityConfig activityConfig = daoMuActivity.getDaoMuActivityConfig();
            if (activityConfig == null) {
                continue;
            }
            ActivityInfo activityInfo = activityConfig.getActivityInfo();
            if (!ActivityHelper.activityInShowTime(activityInfo)) {
                continue;
            }
            //活动配置信息
            DaoMuActivityConfig daoMuActivityConfig = getDaoMuActivityConfig(activityInfo);
            daoMuActivity.initConfig(daoMuActivityConfig);
            getLogger().info("DaoMuActivityMgr reloadConfig success,activityId:{}", activityInfo.getActivityId());
        }
        getLogger().info("DaoMuActivityMgr reloadConfig end");
        return true;
    }

    /**
     * 加载数据
     * @return
     * @throws Exception
     */
    @Override
    public boolean reloadData() throws Exception {
        //盗墓笔记
        Map<Integer, ActivityInfo> activityInfoMap = ActivityMgr.getOpenCrossActivityMapByType(eActivityType.DaoMu.getValue());
        //活动加载进内存
        for (ActivityInfo activityInfo : activityInfoMap.values()) {
            if (ActivityHelper.activityInShowTime(activityInfo)) {
                getActivity(activityInfo.getActivityId());
            }
        }
//        //盗墓奇遇
//        Map<Integer, ActivityInfo> specialActivityInfoMap = ActivityMgr.getOpenCrossActivityMapByType(eActivityType.DaoMuSpecial.getValue());
//        //活动加载进内存
//        for (ActivityInfo activityInfo : specialActivityInfoMap.values()) {
//            reloadActivity(activityInfo.getActivityId());
//        }
        return true;
    }

    /**
     * 获取活动
     * @param activityId
     */
    public static DaoMuActivity getActivity(int activityId) {
        if (!activityMap.containsKey(activityId)) {
            synchronized (activityMap) {
                if (!activityMap.containsKey(activityId)) {
                    ActivityInfo activityInfo = ActivityBussiness.getActivityInfoByActivityId(activityId);
                    if (activityInfo != null) {
                        //活动配置信息
                        DaoMuActivityConfig daoMuActivityConfig = getDaoMuActivityConfig(activityInfo);
                        activityMap.put(activityInfo.getActivityId(), new DaoMuActivity(daoMuActivityConfig));
                    }
                }
            }
        }
        return activityMap.get(activityId);
    }

    @Override
    public boolean save() {
        for (DaoMuActivity daoMuActivity : activityMap.values()) {
            try {
//                daoMuActivity.save();
                DaoMuActivityPvp pvp = daoMuActivity.getDaoMuActivityPvp();
                if (pvp != null) {
                    pvp.save();
                }
            }catch (Exception e){
                getLogger().error("daomu activity {} save err", daoMuActivity.getDaoMuActivityConfig().getActivityId(), e.getCause());
            }
        }
        return true;
    }

    /**
     * 获取盗墓活动配置
     * @param activityInfo
     * @return
     */
    private static DaoMuActivityConfig getDaoMuActivityConfig(ActivityInfo activityInfo) {
        int activityId = activityInfo.getActivityId();
        //活动配置信息
        List<Integer> activityIdList = new ArrayList<>();
        activityIdList.add(activityId);
        Map<String, ActivityConfig> activityConfigMap = ActivityBussiness.getActivityConfigMap(activityIdList).get(activityId);
        //关卡配置
        Map<Integer, DaoMuMissionConfig> missionConfigMap = DaoMuActivityBusiness.getDaoMuMissionConfig(activityId);
        //NPC配置
        Map<Integer, DaoMuNpcConfig> npcConfigMap = DaoMuActivityBusiness.getDaoMuNpcConfig(activityId);
        //藏品配置
        Map<Integer, DaoMuCurioConfig> curioConfigMap = DaoMuActivityBusiness.getDaoMuCurioConfig(activityId);
        //等级配置
        Map<Integer, DaoMuPlayerLevelConfig> levelConfigMap = DaoMuActivityBusiness.getDaoMuPlayerLevelConfig(activityId);
        //技能配置
        Map<Integer, DaoMuSkillConfig> skillConfigMap = DaoMuActivityBusiness.getDaoMuSkillConfig(activityId);
        //开棺宝箱配置
        Map<Integer, DaoMuCrowbarBoxConfig> crowbarBoxConfig = DaoMuActivityBusiness.getDaoMuCrowbarBoxConfig(activityId);
        //开棺宝箱进度配置
        Map<Integer, DaoMuProgressConfig> progressConfig = DaoMuActivityBusiness.getDaoMuProgressConfig(activityId);
        //开棺宝箱进度配置
        Map<Integer, DaoMuCaptainConfig> captainConfig = DaoMuActivityBusiness.getDaoMuCaptainConfig(activityId);
        //PVP配置
        Map<Integer, DaoMuPvpConfig> pvpConfig = DaoMuActivityBusiness.getDaoMuPvpConfig(activityId);
        // pvp技能配置
        Map<Integer, DaoMuPvpSkillConfig> pvpSkillConfig = DaoMuActivityBusiness.getDaoMuPvpSkillConfig(activityId);
        // pvp榜单配置
        Map<Integer, DaoMuPvpRankConfig> pvpRankConfig = DaoMuActivityBusiness.getDaoMuPvpRankConfig(activityId);

        //构造活动配置信息
        return new DaoMuActivityConfig(activityInfo, activityConfigMap, missionConfigMap, npcConfigMap, curioConfigMap, levelConfigMap, skillConfigMap, crowbarBoxConfig, progressConfig, captainConfig, pvpConfig, pvpSkillConfig, pvpRankConfig);
    }

    @Override
    public boolean stop() {
        return false;
    }

    public static Map<Integer, DaoMuActivity> getActivityMap() {
        return activityMap;
    }


//    /**
//     * 进入活动
//     * @param reqMsg
//     * @return
//     */
//    public static DaoMuProto.DaoMuEnterActivityRespMsg.Builder enterActivity(long playerId, DaoMuProto.DaoMuEnterActivityReqMsg reqMsg) {
//        DaoMuProto.DaoMuEnterActivityRespMsg.Builder respMsg = DaoMuProto.DaoMuEnterActivityRespMsg.newBuilder();
//        //获取活动
//        DaoMuActivity daoMuActivity = activityMap.get(reqMsg.getActivityId());
//        if (daoMuActivity == null) {
//            //加载活动
//            daoMuActivity = reloadActivity(reqMsg.getActivityId());
//            if (daoMuActivity == null) {
//                respMsg.setRet(GameErrorCode.E_DAOMU_ACTIVITY_NOT_EXIST);
//                return respMsg;
//            }
//        }
//        //玩家基本信息
//        UserBaseInfo userBaseInfo = PlayerBasePb.parseToUserBaseInfo(reqMsg.getPlayerInfo());
//        // 更新数据
//        CrossUserMgr.updateUserBaseInfo(playerId, userBaseInfo);
//        //获取玩家
//        DaoMuActivityUser daoMuActivityUser = daoMuActivity.getPlayer(playerId);
//        if (daoMuActivityUser == null) {
//            daoMuActivityUser = daoMuActivity.createPlayer(playerId, userBaseInfo, reqMsg.getHistoryMaxPassesId());
//        }
//        respMsg.setRet(0);
//        respMsg.setPlayerInfo(DaoMuActivityPb.createPlayerInfoPb(daoMuActivityUser));
//        return respMsg;
//    }
//
//    /**
//     * 选择角色
//     * @param playerId
//     * @param reqMsg
//     * @return
//     */
//    public static DaoMuProto.DaoMuSelectRoleRespMsg.Builder selectRole(long playerId, DaoMuProto.DaoMuSelectRoleReqMsg reqMsg) {
//        DaoMuProto.DaoMuSelectRoleRespMsg.Builder respMsg = DaoMuProto.DaoMuSelectRoleRespMsg.newBuilder();
//        //获取活动
//        DaoMuActivity daoMuActivity = activityMap.get(reqMsg.getActivityId());
//        if (daoMuActivity == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_ACTIVITY_NOT_EXIST);
//            return respMsg;
//        }
//        //获取玩家
//        DaoMuActivityUser daoMuActivityUser = daoMuActivity.getPlayer(playerId);
//        if (daoMuActivityUser == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PLAYER_NOT_EXIST);
//            return respMsg;
//        }
//        //判断是否在活动进行期
//        if (!ActivityHelper.activityInTime(daoMuActivity.getDaoMuActivityConfig().getActivityInfo())) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_ACTIVITY_NOT_IN_TIME);
//            return respMsg;
//        }
//        try {
//            //选择角色
//            daoMuActivityUser.selectRole(reqMsg.getRoleId());
//            respMsg.setRet(0);
//        } catch (BusinessException e) {
//            respMsg.setRet(e.getCode());
//        }
//        return respMsg;
//    }
//
//    /**
//     * 扫荡
//     * @param playerId
//     * @param reqMsg
//     * @return
//     */
//    public static DaoMuProto.DaoMuMopUpRespMsg.Builder mopUp(long playerId, DaoMuProto.DaoMuMopUpReqMsg reqMsg) {
//        DaoMuProto.DaoMuMopUpRespMsg.Builder respMsg = DaoMuProto.DaoMuMopUpRespMsg.newBuilder();
//        //获取活动
//        DaoMuActivity daoMuActivity = activityMap.get(reqMsg.getActivityId());
//        if (daoMuActivity == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_ACTIVITY_NOT_EXIST);
//            return respMsg;
//        }
//        //获取玩家
//        DaoMuActivityUser daoMuActivityUser = daoMuActivity.getPlayer(playerId);
//        if (daoMuActivityUser == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PLAYER_NOT_EXIST);
//            return respMsg;
//        }
//        synchronized (daoMuActivityUser) {
//            try {
//                //进行扫荡
//                DaoMuReward reward = daoMuActivityUser.mopUp(reqMsg.getPassesId());
//                respMsg.setRet(0);
//                respMsg.setReward(PropertyHelper.parsePropertyToString(reward.getReward()));
//                respMsg.setActivityReward(PropertyHelper.parsePropertyToString(reward.getActivityReward()));
//                respMsg.setPlayerInfo(DaoMuActivityPb.createPlayerInfoPb(daoMuActivityUser));
//            } catch (BusinessException e) {
//                respMsg.setRet(e.getCode());
//            }
//            return respMsg;
//        }
//    }
//
//    /**
//     * 藏品升级
//     * @param playerId
//     * @param reqMsg
//     * @return
//     */
//    public static DaoMuProto.DaoMuCollectionUpgradeRespMsg.Builder collectionUpgrade(long playerId, DaoMuProto.DaoMuCollectionUpgradeReqMsg reqMsg) {
//        DaoMuProto.DaoMuCollectionUpgradeRespMsg.Builder respMsg = DaoMuProto.DaoMuCollectionUpgradeRespMsg.newBuilder();
//        //获取活动
//        DaoMuActivity daoMuActivity = activityMap.get(reqMsg.getActivityId());
//        if (daoMuActivity == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_ACTIVITY_NOT_EXIST);
//            return respMsg;
//        }
//        //获取玩家
//        DaoMuActivityUser daoMuActivityUser = daoMuActivity.getPlayer(playerId);
//        if (daoMuActivityUser == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PLAYER_NOT_EXIST);
//            return respMsg;
//        }
//        //藏品升级
//        try {
//            daoMuActivityUser.collectionUpgrade(reqMsg.getCollectionId());
//            respMsg.setRet(0);
//            respMsg.setPlayerInfo(DaoMuActivityPb.createPlayerInfoPb(daoMuActivityUser));
//        } catch (BusinessException e) {
//            respMsg.setRet(e.getCode());
//        }
//        return respMsg;
//    }
//
//    /**
//     * 使用道具恢复体力
//     * @param playerId
//     * @param reqMsg
//     * @return
//     */
//    public static DaoMuProto.DaoMuUsePropRecoverEnergyRespMsg.Builder usePropRecoverEnergy(long playerId, DaoMuProto.DaoMuUsePropRecoverEnergyReqMsg reqMsg) {
//        DaoMuProto.DaoMuUsePropRecoverEnergyRespMsg.Builder respMsg = DaoMuProto.DaoMuUsePropRecoverEnergyRespMsg.newBuilder();
//        //获取活动
//        DaoMuActivity daoMuActivity = activityMap.get(reqMsg.getActivityId());
//        if (daoMuActivity == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_ACTIVITY_NOT_EXIST);
//            return respMsg;
//        }
//        //获取玩家
//        DaoMuActivityUser daoMuActivityUser = daoMuActivity.getPlayer(playerId);
//        if (daoMuActivityUser == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PLAYER_NOT_EXIST);
//            return respMsg;
//        }
//        int energy = daoMuActivityUser.usePropRecoverEnergy(reqMsg.getProp());
//        respMsg.setRet(0);
//        respMsg.setEnergy(energy);
//        return respMsg;
//    }
//
//    /*********************************************pve局内相关******************************************************/
//
//    /**
//     * PVE-前往探索
//     * @param playerId
//     * @param reqMsg
//     * @return
//     */
//    public static DaoMuProto.DaoMuPveExploreRespMsg.Builder pveExplore(long playerId, DaoMuProto.DaoMuPveExploreReqMsg reqMsg) {
//        DaoMuProto.DaoMuPveExploreRespMsg.Builder respMsg = DaoMuProto.DaoMuPveExploreRespMsg.newBuilder();
//        //获取活动
//        DaoMuActivity daoMuActivity = activityMap.get(reqMsg.getActivityId());
//        if (daoMuActivity == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_ACTIVITY_NOT_EXIST);
//            return respMsg;
//        }
//        //获取玩家
//        DaoMuActivityUser daoMuActivityUser = daoMuActivity.getPlayer(playerId);
//        if (daoMuActivityUser == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PLAYER_NOT_EXIST);
//            return respMsg;
//        }
//        //判断是否在活动进行期
//        if (!ActivityHelper.activityInTime(daoMuActivity.getDaoMuActivityConfig().getActivityInfo())) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_ACTIVITY_NOT_IN_TIME);
//            return respMsg;
//        }
//        synchronized (daoMuActivityUser) {
//            try {
//                //探索处理
//                DaoMuProto.DaoMuPveBattleData.Builder pveBattleData;
//                if (daoMuActivity.getDaoMuActivityConfig().getActivityInfo().getType() == eActivityType.DaoMuSpecial.getValue()) {
//                    //盗墓奇遇（特殊服）
//                    pveBattleData = daoMuActivityUser.exploreSpecial(reqMsg.getPassesId());
//                } else {
//                    //盗墓笔记
//                    pveBattleData = daoMuActivityUser.explore(reqMsg.getPassesId());
//                }
//                //返回PB
//                respMsg.setRet(0);
//                respMsg.setPlayerInfo(DaoMuActivityPb.createPlayerInfoPb(daoMuActivityUser));
//                respMsg.setBattleData(pveBattleData);
//            } catch (BusinessException e) {
//                respMsg.setRet(e.getCode());
//            }
//            return respMsg;
//        }
//    }
//
//    /**
//     * PVE-结算
//     * @param playerId
//     * @param msg
//     * @return
//     */
//    public static DaoMuProto.DaoMuPveAttReportRespMsq.Builder pveAttReport(long playerId,  DaoMuProto.DaoMuPveAttReportReqMsq msg) {
//        DaoMuProto.DaoMuPveAttReportRespMsq.Builder respMsg = DaoMuProto.DaoMuPveAttReportRespMsq.newBuilder();
//        //获取活动
//        DaoMuActivity daoMuActivity = activityMap.get(msg.getActivityId());
//        if (daoMuActivity == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_ACTIVITY_NOT_EXIST);
//            return respMsg;
//        }
//        //获取玩家
//        DaoMuActivityUser daoMuActivityUser = daoMuActivity.getPlayer(playerId);
//        if (daoMuActivityUser == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PLAYER_NOT_EXIST);
//            return respMsg;
//        }
//        synchronized (daoMuActivityUser) {
//            DaoMuProto.DaoMuStatementInfoItem statement = msg.getStatement();
//            Set<Integer> offerNpcSet = new HashSet<>();
//            for (String npcIdStr : statement.getOfferNpcIds().split(";")) {
//                if (!StringUtils.isNullOrEmpty(npcIdStr)) {
//                    offerNpcSet.add(Integer.parseInt(npcIdStr));
//                }
//            }
//            //结算
//            DaoMuProto.DaoMuStatementInfoItem.Builder statementPb = daoMuActivityUser.overPasses(statement.getPassesId(), statement.getStatus(), offerNpcSet, statement.getLevel(), statement.getSkillIds(), statement.getBattleTime(), statement.getKillNum());
//            respMsg.setRet(0);
//            respMsg.setStatement(statementPb);
//            respMsg.setOverFlag(true);
//            respMsg.setActivityId(msg.getActivityId());
//            return respMsg;
//        }
//    }
//
//    /**
//     * 开棺摸金
//     * @param playerId
//     * @param reqMsg
//     * @return
//     */
//    public static DaoMuProto.DaoMuTouchGoldRespMsg.Builder touchGold(long playerId, DaoMuProto.DaoMuTouchGoldReqMsg reqMsg) {
//        DaoMuProto.DaoMuTouchGoldRespMsg.Builder respMsg = DaoMuProto.DaoMuTouchGoldRespMsg.newBuilder();
//        //获取活动
//        DaoMuActivity daoMuActivity = activityMap.get(reqMsg.getActivityId());
//        if (daoMuActivity == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_ACTIVITY_NOT_EXIST);
//            return respMsg;
//        }
//        //获取玩家
//        DaoMuActivityUser daoMuActivityUser = daoMuActivity.getPlayer(playerId);
//        if (daoMuActivityUser == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PLAYER_NOT_EXIST);
//            return respMsg;
//        }
//        synchronized (daoMuActivityUser) {
//            //摸金
//            DaoMuReward daoMuReward = daoMuActivityUser.touchGold(reqMsg.getBoxId(), reqMsg.getNum());
//            //返回PB
//            respMsg.setRet(0);
//            respMsg.setPlayerInfo(DaoMuActivityPb.createPlayerInfoPb(daoMuActivityUser));
//            respMsg.setReward(PropertyHelper.parsePropertyToString(daoMuReward.getReward()));
//            respMsg.setActivityReward(PropertyHelper.parsePropertyToString(daoMuReward.getActivityReward()));
//            return respMsg;
//        }
//    }
//
//    /**
//     * 解锁角色
//     * @param playerId
//     * @param reqMsg
//     * @return
//     */
//    public static DaoMuProto.DaoMuUnlockRoleRespMsg.Builder unlockRole(long playerId, DaoMuProto.DaoMuUnlockRoleReqMsg reqMsg) {
//        DaoMuProto.DaoMuUnlockRoleRespMsg.Builder respMsg = DaoMuProto.DaoMuUnlockRoleRespMsg.newBuilder();
//        //获取活动
//        DaoMuActivity daoMuActivity = activityMap.get(reqMsg.getActivityId());
//        if (daoMuActivity == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_ACTIVITY_NOT_EXIST);
//            return respMsg;
//        }
//        //获取玩家
//        DaoMuActivityUser daoMuActivityUser = daoMuActivity.getPlayer(playerId);
//        if (daoMuActivityUser == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PLAYER_NOT_EXIST);
//            return respMsg;
//        }
//        //判断是否在活动进行期
//        if (!ActivityHelper.activityInTime(daoMuActivity.getDaoMuActivityConfig().getActivityInfo())) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_ACTIVITY_NOT_IN_TIME);
//            return respMsg;
//        }
//        synchronized (daoMuActivityUser) {
//            //解锁角色
//            daoMuActivityUser.unlockRole(reqMsg.getRolePropId());
//            //返回PB
//            respMsg.setRet(0);
//            respMsg.setPlayerInfo(DaoMuActivityPb.createPlayerInfoPb(daoMuActivityUser));
//            return respMsg;
//        }
//    }
//
//    public static void setActivityMap(Map<Integer, DaoMuActivity> activityMap) {
//        DaoMuActivityMgr.activityMap = activityMap;
//    }
//
//    /**
//     * 销毁房间
//     * @param playerId
//     * @param reqMsg
//     * @return
//     */
//    public static DaoMuProto.DaoMuDestroyRoomRespMsg.Builder pveDestroyRoom(long playerId, DaoMuProto.DaoMuDestroyRoomReqMsg reqMsg) {
//        DaoMuProto.DaoMuDestroyRoomRespMsg.Builder respMsg = DaoMuProto.DaoMuDestroyRoomRespMsg.newBuilder();
//        //获取活动
//        DaoMuActivity daoMuActivity = activityMap.get(reqMsg.getActivityId());
//        if (daoMuActivity == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_ACTIVITY_NOT_EXIST);
//            return respMsg;
//        }
//        //获取玩家
//        DaoMuActivityUser daoMuActivityUser = daoMuActivity.getPlayer(playerId);
//        if (daoMuActivityUser == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PLAYER_NOT_EXIST);
//            return respMsg;
//        }
//        synchronized (daoMuActivityUser) {
//            DaoMuProto.DaoMuStatementInfoItem statement = reqMsg.getStatement();
//            //悬赏NPC
//            Set<Integer> offerNpcSet = new HashSet<>();
//            String[] offerNpcIdArr = statement.getOfferNpcIds().split(";");
//            for (String npcIdStr : offerNpcIdArr) {
//                if (!Objects.equals(npcIdStr, "")) {
//                    offerNpcSet.add(Integer.parseInt(npcIdStr));
//                }
//            }
//            //结算
//            DaoMuProto.DaoMuStatementInfoItem.Builder statementPb = daoMuActivityUser.overPasses(statement.getPassesId(), statement.getStatus(), offerNpcSet, statement.getLevel(), statement.getSkillIds(), statement.getBattleTime(), statement.getKillNum());
//            respMsg.setRet(0);
//            respMsg.setStatement(statementPb);
//            return respMsg;
//        }
//    }
//
//    /**
//     * 开启进度宝箱
//     * @param playerId
//     * @param reqMsg
//     * @return
//     */
//    public static DaoMuProto.DaoMuOpenProgressBoxRespMsg.Builder openTouchGoldProgressBox(long playerId, DaoMuProto.DaoMuOpenProgressBoxReqMsg reqMsg) {
//        DaoMuProto.DaoMuOpenProgressBoxRespMsg.Builder respMsg = DaoMuProto.DaoMuOpenProgressBoxRespMsg.newBuilder();
//        //获取活动
//        DaoMuActivity daoMuActivity = activityMap.get(reqMsg.getActivityId());
//        if (daoMuActivity == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_ACTIVITY_NOT_EXIST);
//            return respMsg;
//        }
//        //获取玩家
//        DaoMuActivityUser daoMuActivityUser = daoMuActivity.getPlayer(playerId);
//        if (daoMuActivityUser == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PLAYER_NOT_EXIST);
//            return respMsg;
//        }
//        synchronized (daoMuActivityUser) {
//            Property reward = daoMuActivityUser.openAllTouchGoldProgressBox();
//            respMsg.setRet(0);
//            respMsg.setReward(PropertyHelper.parsePropertyToString(reward));
//            respMsg.setPlayerInfo(DaoMuActivityPb.createPlayerInfoPb(daoMuActivityUser));
//            return respMsg;
//        }
//    }
//
//    /**
//     * 关卡悬赏信息
//     * @param playerId
//     * @param reqMsg
//     * @return
//     */
//    public static DaoMuProto.DaoMuOfferRewardRespMsg.Builder getOfferReward(long playerId, DaoMuProto.DaoMuOfferRewardReqMsg reqMsg) {
//        DaoMuProto.DaoMuOfferRewardRespMsg.Builder respMsg = DaoMuProto.DaoMuOfferRewardRespMsg.newBuilder();
//        //获取活动
//        DaoMuActivity daoMuActivity = activityMap.get(reqMsg.getActivityId());
//        if (daoMuActivity == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_ACTIVITY_NOT_EXIST);
//            return respMsg;
//        }
//        //获取玩家
//        DaoMuActivityUser daoMuActivityUser = daoMuActivity.getPlayer(playerId);
//        if (daoMuActivityUser == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PLAYER_NOT_EXIST);
//            return respMsg;
//        }
//        synchronized (daoMuActivityUser) {
//            Map<Integer, DaoMuActivityUserOfferRewardData> map = daoMuActivityUser.getOfferReward(reqMsg.getPasserId());
//            respMsg.setRet(0);
//            if (map != null) {
//                for (DaoMuActivityUserOfferRewardData offerRewardData : map.values()) {
//                    respMsg.addOfferReward(DaoMuActivityPb.createOfferRewardItemPb(offerRewardData));
//                }
//            }
//            return respMsg;
//        }
//    }
//
//    /**
//     * 领取关卡悬赏信息
//     * @param playerId
//     * @param reqMsg
//     * @return
//     */
//    public static DaoMuProto.DaoMuReceiveOfferRewardRespMsg.Builder receiveOfferReward(long playerId, DaoMuProto.DaoMuReceiveOfferRewardReqMsg reqMsg) {
//        DaoMuProto.DaoMuReceiveOfferRewardRespMsg.Builder respMsg = DaoMuProto.DaoMuReceiveOfferRewardRespMsg.newBuilder();
//        //获取活动
//        DaoMuActivity daoMuActivity = activityMap.get(reqMsg.getActivityId());
//        if (daoMuActivity == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_ACTIVITY_NOT_EXIST);
//            return respMsg;
//        }
//        //获取玩家
//        DaoMuActivityUser daoMuActivityUser = daoMuActivity.getPlayer(playerId);
//        if (daoMuActivityUser == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PLAYER_NOT_EXIST);
//            return respMsg;
//        }
//        synchronized (daoMuActivityUser) {
//            try {
//                DaoMuReward daoMuReward = daoMuActivityUser.receiveOfferReward(reqMsg.getPasserId(), reqMsg.getNpcId());
//                respMsg.setRet(0);
//                respMsg.setReward(PropertyHelper.parsePropertyToString(daoMuReward.getReward()));
//                respMsg.setActivityReward(PropertyHelper.parsePropertyToString(daoMuReward.getActivityReward()));
//                respMsg.setPlayerInfo(DaoMuActivityPb.createPlayerInfoPb(daoMuActivityUser));
//            } catch (BusinessException e) {
//                respMsg.setRet(e.getCode());
//            }
//            return respMsg;
//        }
//    }
//
//    /**
//     * 快速过关
//     * @param playerId
//     * @param reqMsg
//     * @return
//     */
//    public static DaoMuProto.DaoMuQuickPassRespMsg.Builder quickPass(long playerId, DaoMuProto.DaoMuQuickPassReqMsg reqMsg) {
//        DaoMuProto.DaoMuQuickPassRespMsg.Builder respMsg = DaoMuProto.DaoMuQuickPassRespMsg.newBuilder();
//        //获取活动
//        DaoMuActivity daoMuActivity = activityMap.get(reqMsg.getActivityId());
//        if (daoMuActivity == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_ACTIVITY_NOT_EXIST);
//            return respMsg;
//        }
//        //获取玩家
//        DaoMuActivityUser daoMuActivityUser = daoMuActivity.getPlayer(playerId);
//        if (daoMuActivityUser == null) {
//            respMsg.setRet(GameErrorCode.E_DAOMU_PLAYER_NOT_EXIST);
//            return respMsg;
//        }
//        synchronized (daoMuActivityUser) {
//            try {
//                DaoMuProto.DaoMuStatementInfoItem.Builder statement = daoMuActivityUser.quickPass(reqMsg.getPasserId());
//                respMsg.setRet(0);
//                respMsg.setStatement(statement);
//            } catch (BusinessException e) {
//                respMsg.setRet(e.getCode());
//            }
//            return respMsg;
//        }
//    }
}
